/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lolbuilder.mainClasses;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import lolbuilder.Items.Interf.ItemsSuper;
import lolbuilder.build.Build;
import lolbuilder.calculation.LinearCompositionThread;

/**
 *
 * @author chocoboSanMonsterPC
 */
public class ObjectWriterUpdater {
    public static ArrayList<Build> dispoBuilds=new ArrayList<Build>();

    public static void main(String[] args) {
        HashMap<String,Integer> buildsFound=new HashMap<String, Integer>();
        AllItems.populate();
        int size=AllItems.items.size();
        try {
            System.out.println("reading file, plz wait this might take a while...");
            int j=0;
            for (j=0;j<=100;j++) {
                ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("toto"+j+".bin"));
                dispoBuilds.addAll((ArrayList<Build>) inputStream.readObject());
                inputStream.close();
            }
        } catch (Exception ex) {
            Logger.getLogger(ItemBuildGeneratorFromFile.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (Build b : dispoBuilds) {
           ArrayList<String> ss=new ArrayList<String>();
           for (ItemsSuper i : b.items) {
               ss.add(i.name);
           }
           Collections.sort(ss);
           String s="";
           for (String s2 : ss) s+=s2;
           buildsFound.put(s, 1);
        }
        int i=0;
        System.out.println(AllItems.items);
        for (ItemsSuper i0 : AllItems.items) {
            for (ItemsSuper i1 : AllItems.items) {
                for (ItemsSuper i2 : AllItems.items) {
                    for (ItemsSuper i3 : AllItems.items) {
                        for (ItemsSuper i4 : AllItems.items) {
                            for (ItemsSuper i5 : AllItems.items) {
                               ArrayList<String> ss= new ArrayList<String>();
                                
                               ss.add(i0.name);
                               ss.add(i1.name);
                               ss.add(i2.name);
                               ss.add(i3.name);
                               ss.add(i4.name);
                               ss.add(i5.name);
                               Collections.sort(ss);
                               String s="";
                               for (String s2 : ss) s+=s2;
                               if (buildsFound.get(s)==null) {
                                   buildsFound.put(s, 1);
                                   Build tmp=new Build();
                                    tmp.items.add(i0);
                                    tmp.items.add(i1);
                                    tmp.items.add(i2);
                                    tmp.items.add(i3);
                                    tmp.items.add(i4);
                                    tmp.items.add(i5);
                                    
                                    dispoBuilds.add(tmp);
                                    tmp=null;
                                }
                            }
                        }
                    }
                }
            }
            i++;
            System.out.println(""+((((float)i)/size)*100)+"% done");
            
       }
        try {
            int ii=0;
            int cpt=0;
            int sizei=dispoBuilds.size();
            ArrayList<Build> tmp=new ArrayList<Build>();
            for (Build b : dispoBuilds) {
                tmp.add(b);
                if (ii%(sizei/100) ==0 ) {
                    ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("toto"+cpt+".bin"));
                    oos.writeObject(tmp);
                    oos.flush();
                    oos.close();
                    tmp=new ArrayList<Build>();
                    cpt++;
                }
                ii++;
            }
            
        } catch (IOException ex) {
            Logger.getLogger(LinearCompositionThread.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
}
